﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using WinnerCMS.Common;
using WinnerCMS.Data;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_ContentProperty 的摘要说明。
    /// </summary>
    public class ContentPropertyManage
    {
        private static readonly ContentPropertyDal Dal = new ContentPropertyDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public Result Add(ContentProperty model)
        {
            Result resu = new Result();
            if (model.Name.Length == 0)
            {
                resu.Errors = "“名字”不能为空！";
                return resu;
            }
            model.UpDateTime = DateTime.Now;
            if (model.Id == 0)
            {
                int i = Dal.Add(model);
                if (i == 0)
                {
                    resu.Errors = "已经有相同的数据！";
                    return resu;
                }
            }
            else
            {
                Dal.Edit(model);
            }

            return resu;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public Result Delete(string ID)
        {
            Result res = new Result();
            if (string.IsNullOrEmpty(ID))
            {
                res.Errors = "至少选择一项。";
            }
            else
            {
                Dal.Delete(int.Parse(ID));
            }
            return res;
        }

        #endregion

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="modelId"></param>
        /// <param name="type"></param>
        /// <param name="keyword"></param>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<ContentProperty> BindList(byte modelId, ContentPropertyOption type, string keyword, PagingParam pp)
        {
            return Dal.BindList(modelId, (int) type, keyword, pp);
        }
    }
}